#include <stdio.h>
#include <stdlib.h>

#define JOSE_NUM 8

struct node_st
{
    int data;
    struct node_st * next;
};

struct node_st * jose_create(int num)
{
    struct node_st *me,*newnode,*cur;
    int i = 1;
    me = malloc(sizeof(*me));
    if(me == NULL) return NULL;
    me->data = i;
    me->next = me;
    ++i;
    cur = me;
    for(;i <= num;++i){
        newnode = malloc(sizeof(*newnode));
        if(newnode == NULL){
            return NULL;
        }
        newnode->data = i;
        newnode->next = me;
        cur->next = newnode;
        cur = newnode;
    }
    return me;


}
void jose_show(struct node_st *me)
{
    struct node_st *list = me;
    for(;list->next != me;list = list->next){
        printf("%d ",list->data);
        // sleep(1);
        // fflush(NULL);
    }
    printf("%d\n",list->data);

}

void jose_kill(struct node_st **me,int n)
{
    struct node_st *cur = *me,*node;
    int i = 1;
    while(cur != cur->next){
        while(i < n){
            node = cur;
            cur = cur->next;
            ++i;
        }
        printf("%d ",cur->data);
        node->next = cur->next;
        free(cur);
        cur = node->next;
        i = 1;
    }
    printf("\n");
    *me = cur;
}
int main()
{
    int n = 3;
    struct node_st *list;
    list = jose_create(JOSE_NUM);
    if(list == NULL){
        exit(1);
    }
    jose_show(list);
    jose_kill(&list,n);
    jose_show(list);
    exit(0);
}